package com.ztn.sdk.iot.api;

import com.fasterxml.jackson.core.type.TypeReference;
import com.ztn.sdk.iot.api.util.HttpTool;
import com.ztn.sdk.iot.api.res.DeviceSendRes;
import com.ztn.sdk.iot.api.req.DeviceSettingListReq;
import com.ztn.sdk.iot.api.req.DeviceSettingSendReq;
import com.ztn.sdk.iot.api.res.BaseRes;
import com.ztn.sdk.iot.api.res.DeviceSettingWithParamList;
import com.ztn.sdk.iot.api.util.JsonTool;

import java.util.ArrayList;
import java.util.List;

public class IotDeviceSettingTool {

    private static final String BASE_PATH = "iot/api/v1/v1/device/setting/";


    public static List<DeviceSettingWithParamList> list(DeviceSettingListReq req) {
        String path = BASE_PATH + "list";
        BaseRes<List<DeviceSettingWithParamList>> res = HttpTool.doPost(path, JsonTool.toJson(req), new TypeReference<BaseRes<List<DeviceSettingWithParamList>>>() {
        });
        if (null != res && null != res.data) {
            return res.data;
        }
        return new ArrayList<>();
    }

    public static DeviceSendRes send(DeviceSettingSendReq req) {
        String path = BASE_PATH + "send";
        BaseRes<DeviceSendRes> res = HttpTool.doPost(path, JsonTool.toJson(req), new TypeReference<BaseRes<DeviceSendRes>>() {
        });
        if (null != res && null != res.data) {
            return res.data;
        }
        return null;
    }
}
